/**
 * Created by zhourh on 2018/5/23.
 */
public class FlippingImage {

    public static void main(String[] args) {
        int[][] A = new int[][]{{1,1,0,0}, {1,0,0,1}, {0,1,1,1}, {1,0,1,0}};
        int[][] R = new FlippingImage().flipAndInvertImage(A);
        for (int i = 0; i < R.length; i++) {
            int[] L = R[i];
            for (int j = 0; j < L.length; j++) {
                System.out.print(L[j] +  ", ");
            }
            System.out.println();
        }

    }

    public int[][] flipAndInvertImage(int[][] A) {
        for (int i = 0; i < A.length; i++ ) {
            flipAndInvertImage(A[i]);
        }

        return A;
    }

    public int[] flipAndInvertImage(int[] A) {
        if (A == null || A.length <= 0) {
            return A;
        }

        for (int i = 0, j = A.length - 1; i <= j; i++, j--) {
            int t = A[i];
            A[i] = A[j] ^ 0x01;
            if (i != j) {
                A[j] = t ^ 0x01;
            }
        }

        return A;
    }


}
